//package com.gitee.feizns.quickstart.utils.dingtalk.api;
//
//import com.gitee.feizns.quickstart.utils.dingtalk.oauth.V1OAuth2;
//import lombok.RequiredArgsConstructor;
//
///**
// * 服务端API > 宜搭应用开发 > 概述
// * <a href="https://open.dingtalk.com/document/isvapp/overview-yida">宜搭应用开发</a>
// * @author feizns
// * @since 2022/12/30
// */
//@RequiredArgsConstructor
//public class YiDaUtils {
//
//    /**
//     * {@link V1OAuth2}
//     */
//    private final V1OAuth2 v1OAuth2;
//
//    /**
//     * 流程
//     */
//    public ProcessesApi processesApi = new ProcessesApi();
//
//    /**
//     * 表单
//     */
//    public FormsApi formsApi = new FormsApi();
//
//    /**
//     * 服务端API > 宜搭应用开发 > 流程
//     * @return {@link ProcessesApi}
//     */
//    public ProcessesApi processes() {
//        return processesApi;
//    }
//
//    /**
//     * 服务端API > 宜搭应用开发 > 表单
//     * @return {@link ProcessesApi}
//     */
//    public FormsApi form() {
//        return formsApi;
//    }
//
//    /**
//     * 服务端API > 宜搭应用开发 > 流程
//     * @author feizns
//     * @since 2023/07/18
//     */
//    public class ProcessesApi {
//
//    }
//
//    /**
//     * 表单
//     * @author feizns
//     * @since 2023/07/18
//     */
//    public class FormsApi {
//
////        /**
////         * 插入
////         * @param formUuid uuid形式
////         * @param data 数据
////         * @return {@link SaveFormDataResponseBody}
////         */
////        public SaveFormDataResponseBody insert(String formUuid, Map<String, Object> data) {
////            SaveFormDataHeaders saveFormDataHeaders = new SaveFormDataHeaders();
////            saveFormDataHeaders.xAcsDingtalkAccessToken = v1OAuth2.accessToken().get();
////            SaveFormDataRequest saveFormDataRequest = new SaveFormDataRequest()
////                    .setAppType(v1OAuth2.getConfig().getAppType())
////                    .setSystemToken(v1OAuth2.getConfig().getSystemToken())
////                    .setUserId(v1OAuth2.getConfig().getUserId())
////                    .setLanguage(v1OAuth2.getConfig().getLanguage())
////                    .setFormUuid(formUuid)
////                    .setFormDataJson(JsonUtils.toJson(data));
////            SaveFormDataResponse response = ClientManager.getClient().saveFormDataWithOptions(saveFormDataRequest, saveFormDataHeaders, new RuntimeOptions());
////            return response.getBody();
////        }
//
////
////        /**
////         * 清空表单数据
////         * @param frmUuid 纳uuid
////         */
////        public void clear(String frmUuid) {
////            List<String> instanceIds = instanceIds(frmUuid);
////            List<List<String>> lists = ListUtils.partition(instanceIds, 500);
////            for (List<String> ids : lists) {
////                deleteByIds(frmUuid, ids.toArray(String[]::new));
////                System.out.println("删除数据：" + ids);
////            }
////        }
////
////        /**
////         * 删除通过实例编号
////         * @param ids 编号列表
////         */
////        public void deleteByIds(String frmUuid, String... ids) {
////            BatchRemovalByFormInstanceIdListHeaders batchRemovalByFormInstanceIdListHeaders = new BatchRemovalByFormInstanceIdListHeaders();
////            batchRemovalByFormInstanceIdListHeaders.xAcsDingtalkAccessToken = v1OAuth2.getAccessToken();
////            BatchRemovalByFormInstanceIdListRequest batchRemovalByFormInstanceIdListRequest = new BatchRemovalByFormInstanceIdListRequest()
////                    .setFormUuid(frmUuid)
////                    .setAppType(config.getAppType())
////                    .setAsynchronousExecution(true)
////                    .setSystemToken(config.getSystemToken())
////                    .setFormInstanceIdList(Arrays.asList(ids))
////                    .setUserId(config.getUserId())
////                    .setExecuteExpression(false);
////            try {
////                client.batchRemovalByFormInstanceIdListWithOptions(batchRemovalByFormInstanceIdListRequest, batchRemovalByFormInstanceIdListHeaders, new RuntimeOptions());
////            } catch (Exception e) {
////                throw new RuntimeException(e);
////            }
////        }
////
////        /**
////         * 通过表单实例编号更新
////         * @param formInstanceId 形式实例编号
////         * @param data 数据
////         */
////        public void updateById(String formInstanceId, Map<String, Object> data) {
////            UpdateFormDataHeaders updateFormDataHeaders = new UpdateFormDataHeaders();
////            updateFormDataHeaders.xAcsDingtalkAccessToken = v1OAuth2.getAccessToken();
////            UpdateFormDataRequest updateFormDataRequest = new UpdateFormDataRequest()
////                    .setAppType(config.getAppType())
////                    .setSystemToken(config.getSystemToken())
////                    .setUserId(config.getUserId())
////                    .setLanguage(config.getLanguage())
////                    .setFormInstanceId(formInstanceId)
////                    .setUpdateFormDataJson(JsonUtils.toJson(data));
////            try {
////                client.updateFormDataWithOptions(updateFormDataRequest, updateFormDataHeaders, new RuntimeOptions());
////            } catch (Exception e) {
////                throw new RuntimeException(e);
////            }
////        }
////
////        /**
////         * 根据条件抓取所有列表数据
////         * @param formUuid uuid形式
////         * @param conditions 条件
////         * @return {@link List}<{@link GetFormDataByIDResponseBody}>
////         */
////        public List<BatchGetFormDataByIdListResponseBody.BatchGetFormDataByIdListResponseBodyResult> getList(String formUuid, SearchCondition... conditions) {
////            List<String> instanceIds = instanceIds(formUuid, conditions);
////            if ( CollectionUtils.isEmpty(instanceIds) )
////                return Collections.emptyList();
////            return getByIds(formUuid, instanceIds.toArray(String[]::new));
////        }
////
////        /**
////         * 根据条件抓一条数据
////         * @param formUuid uuid形式
////         * @param conditions 条件
////         * @return {@link GetFormDataByIDResponseBody}
////         */
////        public GetFormDataByIDResponseBody getOne(String formUuid, SearchCondition... conditions) {
////            List<String> instanceIds = instanceIds(formUuid, conditions);
////            return CollectionUtils.isEmpty(instanceIds) ? null : getById(instanceIds.get(0));
////        }
////
////        /**
////         * 是否存在指定条件的数据
////         * @param fromUuid 从uuid
////         * @param conditions 条件
////         * @return boolean
////         */
////        public boolean exists(String fromUuid, SearchCondition... conditions) {
////            List<String> instanceIds = instanceIds(fromUuid, conditions);
////            return !CollectionUtils.isEmpty(instanceIds);
////        }
////
////        /**
////         * 得到通过编号
////         * 得到形式数据通过编号
////         * @param formInstanceId 形式实例编号
////         * @return {@link GetFormDataByIDResponseBody}
////         */
////        public GetFormDataByIDResponseBody getById(String formInstanceId) {
////            GetFormDataByIDHeaders getFormDataByIDHeaders = new GetFormDataByIDHeaders();
////            getFormDataByIDHeaders.xAcsDingtalkAccessToken = v1OAuth2.getAccessToken();
////            GetFormDataByIDRequest getFormDataByIDRequest = new GetFormDataByIDRequest()
////                    .setAppType(config.getAppType())
////                    .setSystemToken(config.getSystemToken())
////                    .setUserId(config.getUserId())
////                    .setLanguage(config.getLanguage());
////            try {
////                return client
////                        .getFormDataByIDWithOptions(formInstanceId, getFormDataByIDRequest, getFormDataByIDHeaders, new RuntimeOptions())
////                        .getBody();
////            } catch (Exception err) {
////                throw new RuntimeException(err);
////            }
////        }
////
////        /**
////         * 插入或更新
////         * @param fromUuid 从uuid
////         * @param data 数据
////         * @param condition 条件
////         * @return {@link List}<{@link String}>
////         */
////        @SneakyThrows
////        public List<String> insertOrUpdate(String fromUuid, Map<String, Object> data, SearchCondition... condition) {
////            CreateOrUpdateFormDataHeaders createOrUpdateFormDataHeaders = new CreateOrUpdateFormDataHeaders();
////            createOrUpdateFormDataHeaders.xAcsDingtalkAccessToken = v1OAuth2.getAccessToken();
////            CreateOrUpdateFormDataRequest createOrUpdateFormDataRequest = new CreateOrUpdateFormDataRequest()
////                    .setNoExecuteExpression(false)
////                    .setFormUuid(fromUuid)
////                    .setSearchCondition(JSON.toJSONString(Arrays.asList(condition)))
////                    .setAppType(config.getAppType())
////                    .setFormDataJson(JSON.toJSONString(data))
////                    .setSystemToken(config.getSystemToken())
////                    .setUserId(config.getUserId());
////            CreateOrUpdateFormDataResponse options = client.createOrUpdateFormDataWithOptions(createOrUpdateFormDataRequest, createOrUpdateFormDataHeaders, new RuntimeOptions());
////            return options.getBody().getResult();
////        }
////
////        /**
////         * 实例编号列表
////         * @param fromUuid 从uuid
////         * @param conditions 条件
////         * @return {@link List}<{@link String}>
////         */
////        @SneakyThrows
////        public List<String> instanceIds(String fromUuid, SearchCondition... conditions) {
////            return instanceIds(fromUuid, null, null, null, null,conditions);
////        }
////
////        /**
////         * 实例编号列表
////         * @param fromUuid 从uuid
////         * @param createFromTimeGMT 格林尼治时间创建时间
////         * @param createToTimeGMT 格林尼治时间创建时间
////         * @param conditions 条件
////         * @return {@link List}<{@link String}>
////         */
////        @SneakyThrows
////        public List<String> instanceIds(String fromUuid, String createFromTimeGMT, String createToTimeGMT, String modifiedFromTimeGMT, String modifiedToTimeGMT, SearchCondition... conditions) {
////            List<String> result = new ArrayList<>();
////            instanceIds(fromUuid, createFromTimeGMT, createToTimeGMT, modifiedFromTimeGMT, modifiedToTimeGMT, result::add, conditions);
////            return result;
////        }
////
////        /**
////         * 实例编号列表
////         * @param fromUuid 从uuid
////         * @param createFromTimeGMT 格林尼治时间创建时间
////         * @param createToTimeGMT 格林尼治时间创建时间
////         * @param conditions 条件
////         * @return {@link List}<{@link String}>
////         */
////        @SneakyThrows
////        public List<String> instanceIds(String fromUuid, String createFromTimeGMT, String createToTimeGMT, SearchCondition... conditions) {
////            List<String> result = new ArrayList<>();
////            instanceIds(fromUuid, createFromTimeGMT, createToTimeGMT, null, null, result::add, conditions);
////            return result;
////        }
////
////        /**
////         * 实例编号列表
////         * @param fromUuid 从uuid
////         * @param createFromTimeGMT 格林尼治时间创建时间
////         * @param createToTimeGMT 格林尼治时间创建时间
////         * @param conditions 条件
////         */
////        @SneakyThrows
////        public void instanceIds(String fromUuid, String createFromTimeGMT, String createToTimeGMT, String modifiedFromTimeGMT, String modifiedToTimeGMT, Consumer<String> consumer, SearchCondition... conditions) {
////            int maxPageSize = 100;
////            int current = 1;
////            long total = 0;
////            do {
////                SearchFormDataIdListHeaders searchFormDataIdListHeaders = new SearchFormDataIdListHeaders();
////                searchFormDataIdListHeaders.xAcsDingtalkAccessToken = v1OAuth2.getAccessToken();
////                SearchFormDataIdListRequest searchFormDataIdListRequest = new SearchFormDataIdListRequest()
////                        .setSystemToken(config.getSystemToken())
////                        .setLanguage(config.getLanguage())
////                        .setUserId(config.getUserId())
////                        .setSearchFieldJson(JSON.toJSONString(Arrays.asList(conditions)))
////                        .setPageNumber(current)
////                        .setPageSize(maxPageSize);
////                if ( createFromTimeGMT != null )
////                    searchFormDataIdListRequest.setCreateFromTimeGMT(createFromTimeGMT);
////                if ( createToTimeGMT != null )
////                    searchFormDataIdListRequest.setCreateToTimeGMT(createToTimeGMT);
////                if ( modifiedFromTimeGMT != null )
////                    searchFormDataIdListRequest.setModifiedFromTimeGMT(modifiedFromTimeGMT);
////                if ( modifiedToTimeGMT != null )
////                    searchFormDataIdListRequest.setModifiedToTimeGMT(modifiedToTimeGMT);
////                //
////                SearchFormDataIdListResponse resp = client.searchFormDataIdListWithOptions(config.getAppType(), fromUuid, searchFormDataIdListRequest, searchFormDataIdListHeaders, new RuntimeOptions());
////                SearchFormDataIdListResponseBody body = resp.getBody();
////                total = body.getTotalCount();
////                body.data.forEach(consumer);
////            } while ( (long) current++ * maxPageSize < total );
////        }
////
////        /**
////         * 得到通过编号列表
////         * @param fromUuid 从uuid
////         * @param instanceIds 实例编号列表
////         * @return {@link List}<{@link BatchGetFormDataByIdListResponseBody.BatchGetFormDataByIdListResponseBodyResult}>
////         */
////        @SneakyThrows
////        public List<BatchGetFormDataByIdListResponseBody.BatchGetFormDataByIdListResponseBodyResult> getByIds(String fromUuid, String... instanceIds) {
////            BatchGetFormDataByIdListHeaders headers = new BatchGetFormDataByIdListHeaders();
////            headers.xAcsDingtalkAccessToken = v1OAuth2.getAccessToken();
////            BatchGetFormDataByIdListRequest request = new BatchGetFormDataByIdListRequest()
////                    .setFormUuid(fromUuid)
////                    .setAppType(config.getAppType())
////                    .setSystemToken(config.getSystemToken())
////                    .setFormInstanceIdList(Arrays.asList(instanceIds))
////                    .setNeedFormInstanceValue(true)
////                    .setUserId(config.getUserId());
////            BatchGetFormDataByIdListResponse resp = client.batchGetFormDataByIdListWithOptions(request, headers, new RuntimeOptions());
////            return resp.getBody().getResult();
////        }
//
//    }
//
//}
